﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LogicaNegocio;
using DAO;

namespace Minutero
{
    public partial class FormAltaNota : Form
    {
        bool cerro = false;
        public static int idReunion;
        Form form;// = new frmAgenda(null, null);
        bool edit;
        public FormAltaNota()
        {
            InitializeComponent();
        }
        public FormAltaNota(int r, Form f, bool editar)
        {
            InitializeComponent();
            lblIdReunion.Text = "" + r;
            idReunion = r;
            form = f;
            edit = editar;
            txtContenido.RichTextShortcutsEnabled = true;
        }
        private void FormAltaNota_Load(object sender, EventArgs e)
        {
            txtContenido.Rtf = Gestor.MostrarNota(idReunion);
            if (edit)
            {
                btnGuardar.Enabled = false;
            }
        }


        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                string contenido = txtContenido.Text;

                //if (Gestor.AgregarNota(idReunion, contenido))
                if(Gestor.AgregarNota(idReunion,txtContenido.Rtf))
                {
                    txtContenido.Text = "";
                    lbl_AltaNota.Visible = true;
                    lbl_AltaNota.Text = "Se agrego correctamente";
                }
                else
                {
                    lbl_AltaNota.Visible = true;
                    lbl_AltaNota.Text = "No se pudo agregar la nota";
                }
            }
            catch (ArgumentException arg) { }
            catch (Exception ex) { }

            form.Show();
            cerro = true;
            this.Close();
        }

        private void btn_Cancelar_Click(object sender, EventArgs e)
        {
            form.Show();
            cerro = true;
            this.Close();

        }

        private void FormAltaNota_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (!cerro)
            {
                form.Show();
                this.Visible = false;
            }
        }

        private void txtNombreNota_TextChanged(object sender, EventArgs e)
        {
            lbl_AltaNota.Visible = false;
        }

        private void btn_accion_Click(object sender, EventArgs e)
        {
            AltaAccion ac = new AltaAccion(idReunion);
            ac.Show();
        }

        private void btnFuente_Click(object sender, EventArgs e)
        {
            FontDialog fontDialog1 = new FontDialog();
            if (fontDialog1.ShowDialog() == DialogResult.OK)
            {
                if (txtContenido.SelectedText != "")
                {
                    txtContenido.SelectionFont = fontDialog1.Font;
                }
                else
                {
                    txtContenido.Font = fontDialog1.Font;
                }
            }
        }

       

    }
}
